#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
using ll = long long;
ll a, b, p;
ll qadd(ll a, ll b, ll p)
{
    ll res = 0;
    while (b)
    {
        if (b & 1) res = (res + a) % p;
        a = (a + a) % p;
        b >>= 1;
    }
    return res;
}
int main()
{
    cin >> a >> b >> p;
    cout << qadd(a, b, p) << endl;
    return 0;
}
